package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.AdminWeeklyJob;
import com.ruoyi.system.service.IAdminWeeklyJobService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 周报任务工作Controller
 * 
 * @author ruoyi
 * @date 2021-01-20
 */
@Controller
@RequestMapping("/system/job")
public class AdminWeeklyJobController extends BaseController
{
    private String prefix = "system/job";

    @Autowired
    private IAdminWeeklyJobService adminWeeklyJobService;

    @RequiresPermissions("system:job:view")
    @GetMapping()
    public String job()
    {
        return prefix + "/job";
    }

    /**
     * 查询周报任务工作列表
     */
    @RequiresPermissions("system:job:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AdminWeeklyJob adminWeeklyJob)
    {
        startPage();
        List<AdminWeeklyJob> list = adminWeeklyJobService.selectAdminWeeklyJobList(adminWeeklyJob);
        return getDataTable(list);
    }

    /**
     * 导出周报任务工作列表
     */
    @RequiresPermissions("system:job:export")
    @Log(title = "周报任务工作", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AdminWeeklyJob adminWeeklyJob)
    {
        List<AdminWeeklyJob> list = adminWeeklyJobService.selectAdminWeeklyJobList(adminWeeklyJob);
        ExcelUtil<AdminWeeklyJob> util = new ExcelUtil<AdminWeeklyJob>(AdminWeeklyJob.class);
        return util.exportExcel(list, "job");
    }

    /**
     * 新增周报任务工作
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存周报任务工作
     */
    @RequiresPermissions("system:job:add")
    @Log(title = "周报任务工作", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AdminWeeklyJob adminWeeklyJob)
    {
        return toAjax(adminWeeklyJobService.insertAdminWeeklyJob(adminWeeklyJob));
    }

    /**
     * 修改周报任务工作
     */
    @GetMapping("/edit/{jobId}")
    public String edit(@PathVariable("jobId") Long jobId, ModelMap mmap)
    {
        AdminWeeklyJob adminWeeklyJob = adminWeeklyJobService.selectAdminWeeklyJobById(jobId);
        mmap.put("adminWeeklyJob", adminWeeklyJob);
        return prefix + "/edit";
    }

    /**
     * 修改保存周报任务工作
     */
    @RequiresPermissions("system:job:edit")
    @Log(title = "周报任务工作", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AdminWeeklyJob adminWeeklyJob)
    {
        return toAjax(adminWeeklyJobService.updateAdminWeeklyJob(adminWeeklyJob));
    }

    /**
     * 删除周报任务工作
     */
    @RequiresPermissions("system:job:remove")
    @Log(title = "周报任务工作", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(adminWeeklyJobService.deleteAdminWeeklyJobByIds(ids));
    }
}
